<div  ng-app="myApp" ng-controller="myController">
<div class="Item hr">
    <span class="fr">现有小说<b>{$rows_count}</b>部</span>
    <div class="current">小说列表</div>
    <php>if($rank_id){</php>
        <div class="current"><a ng-click="show_novels()" href="javascript:void(0);">添加榜单小说</a></div>
    <php>}</php>
</div>
<form>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab">
        <thead>
            <tr>
                <td>ID</td>
                <td>小说名称</td>
                <td>作者</td>
                <td>是否完结</td>
                <td>是否连载</td>
                <td>来源名称</td>
                <td>来源网址</td>
                <td>字数</td>
                <td>阅读人数</td>
                <td>收藏数</td>
                <td>所属分类</td>
                <td>适合人群</td>
                <td>是否推荐</td>
                <td>推荐时间</td>
                <td>添加时间</td>
                <td>更新时间</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <volist name="novel" id="val">
            <tr align="center">
                <td>{$val['id']}</td>
                <td>{$val['title']}</td>
                <td>{$val['author']}</td>
                <td><?php echo $val['is_finish']==1?"是":"否";?></td>
                <td><?php echo $val['is_serial']==1?"是":"否";?></td>
                <td>{$val['source_addr']}</td>
                <td>{$val['source_url']}</td>
                <td>{$val['words_number']}</td>
                <td>{$val['read_number']}</td>
                <td>{$val['collect_number']}</td>
                <td>{$val['class_id']}</td>
                <td>
                    <?php
                        switch($val['fit_crowd']){
                            case 0: echo "都合适";break;
                            case 1: echo "男";break;
                            case 2: echo "女";break;
                        }
                    ?>
                </td>
                <td><?php echo $val['is_recommend']==1?"是":"否";?></td>
                <td>{:date('Y-m-d H:i:s', $val['recommend_time'])}</td>
                <td>{:date('Y-m-d H:i:s', $val['create_time'])}</td>
                <td>{:date('Y-m-d H:i:s', $val['update_time'])}</td>
                <td>
                    [ <a href="{:U('Novel/edit', array('id' => $val['id']))}">详情</a> ]
                    <php>if($_SESSION['current_account']['is_super'] == 1){</php>
                    <php>if($rank_id){</php>
                    || [ <a onclick="remove_rank({$rank_id},{$val.id})" href="javascript:void(0)">移出榜单</a> ]
                    <php>}else{</php>
                    || [ <a onclick="del({$val.id})" href="javascript:void(0)">删除</a> ]
                    <php>}</php>
                    || [ <a href="{:U('Novel/chapter_index', array('novel_id' => $val['id']))}">小说章节</a> ]
                    <php>}</php>
                </td>
            </tr>
            </volist>
        </tbody>
    </table>
</form>

<!--搜索小说弹框-->
<div id="novel_box" style="display: none; margin-top: 100px;" >
    <center><input style="height: 30px;" ng-model="data.keyword" placeholder="&nbsp;请输入要搜索的小说名称"><input style="width: 50px; height: 30px;margin-left: 10px;" type='button' id="submit_novel" ng-click="search_novel();" value='搜索'></center>
    <center> <select ng-model="data.novel_id" style="width: 235px;display: none;margin-top: 10px;" id="show_novel_list">
        <option value="" selected>请选择小说</option>
        <option ng-repeat="item in novel_list" value="{{item.id}}">{{item.title}}</option>
    </select></center>
    <center><input type='button'  style="width: 50px; height: 30px; margin-top: 40px;" ng-click="submit_novel();" value='确定'></center>
</div>

<div class="page">
    {$page}
</div>
</div>
<script type="text/javascript" src="__PUBLIC__/javascripts/admin/layer/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/javascripts/admin/angular.min.js"></script>
<script type="text/javascript">
    function del(id){
        layer.confirm('确定要删除此小说?', {icon: 3, title:'提示'}, function( )
        {
            $.post(
                "{:U('Novel/del')}",{id:id},function(json){
                    if(json.code == 0){
                        layer.msg(json.msg,{icon:1,time: 1000},function(){location.reload()});
                    }
                },'json'
            )
            layer.close();//关闭弹窗
        });
    }

    function remove_rank(rank_id,novel_id){
        layer.confirm('确定要将对应小说移出榜单?', {icon: 3, title:'提示'}, function( )
        {
            $.post(
                "{:U('Rank/remove_rank')}",{rank_id:rank_id,novel_id:novel_id},function(json){
                    if(json.code == 0){
                        layer.msg(json.msg,{icon:1,time: 1000},function(){location.reload()});
                    }
                },'json'
            )
            layer.close();//关闭弹窗
        });
    }

    var app = angular.module('myApp',[]);
    app.controller('myController',function($scope){
        $scope.data = {keyword:''};
        $scope.novel_list = [{id:'',title:''}];     //小说列表
        $scope.show_novels = function(){
            layer.open({
                type: 1,
                title: false,
                closeBtn: 1,
                area: ["500px", "320px"],
                shadeClose: false,
                content:$('#novel_box')
            });

            //搜索小说
            $scope.search_novel = function(){
                if($scope.data.keyword == ''){
                    layer.alert("请输入搜索内容",{icon:2});return false;
                }

                $.post("{:U('Novel/search_novels')}",{keyword:$scope.data.keyword},function(data){
                    if(data.code == 0){
                        $('#show_novel_list').show();
                        $scope.$apply(function(){
                            $scope.novel_list = data.list;
                        })
                    }else{
                        layer.alert(data.msg,{icon:2});
                    }
                },'json')
            }

            //提交信息
            $scope.submit_novel = function(){
                var rank_id = {$rank_id};
                var novel_id = $scope.data.novel_id;

                if(novel_id == 0 || novel_id == '' || novel_id == undefined){
                    layer.alert("请选择小说！",{icon:2});return false;
                }
                $.post("{:U('Rank/add_rank_novel')}",{rank_id:rank_id,novel_id:$scope.data.novel_id},function(data){
                    if(data.code == 0){
                        layer.alert(data.msg,{icon:1});
                    }else{
                        layer.alert(data.msg,{icon:2});
                    }
                },'json')
            }
        }
    });

</script>
